import router from '@/router'
import {post} from '@/util/request'
import moment from 'moment'

export default {
	namespace:'accidentStat',
	namespaced:true,
	state:{
		isLoading:false,
		isModalLoading:false,
    typeList:[],
    driverPagedata:{}
	},
	mutations:{
		changeLoading(state,v){
			state.isLoading = v;
		},
		changeModalLoading(state,v){
			state.isModalLoading = v;
		},
    chagneTypelist(state,v){
      state.typeList = v;
    },
    changeDriverPagedata(state,v){
      state.driverPagedata = v;
    }
	},
	actions:{
    async reload({commit},query){
      commit('changeLoading',true);
      let tres = await post('/base/stat/accidentTypeList',query);
      let dres = await post('/base/stat/driverList',query);
      commit('chagneTypelist',tres.data.data);
      commit('changeDriverPagedata',dres.data.data);
      commit('changeLoading',false);
    },
    async reloadDriver({commit},query){
      commit('changeLoading',true);
      let dres = await post('/base/stat/driverList',query);
      commit('changeDriverPagedata',dres.data.data);
      commit('changeLoading',false);
    }
	},
	subscriptions({dispatch},router){
		//给路由加监听一旦进入module绑定的页面时dispatch初始化action
		router.afterEach((to,from)=>{
			if(to.name === this.namespace){

			}
		})
	}
}
